<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-flash.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
    
  
  <link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.css" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  
    
      
    

    
  

  

  

  
    
      
    

    
  

  
    
    
    <link href="https://fonts.cat.net/css?family=Lato:300,300italic,400,400italic,700,700italic|Roboto Slab:300,300italic,400,400italic,700,700italic|Roboto Mono:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="XLForm," />










<meta name="description" content="这次来点特别的">
<meta name="keywords" content="XLForm">
<meta property="og:type" content="article">
<meta property="og:title" content="XLForm 表单库的复杂使用 - 地址选择器">
<meta property="og:url" content="http:&#x2F;&#x2F;urm9ril.top&#x2F;2017&#x2F;06&#x2F;25&#x2F;XLForm-Complex-AreaPicker&#x2F;index.html">
<meta property="og:site_name" content="ooops 的小站">
<meta property="og:description" content="这次来点特别的">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http:&#x2F;&#x2F;q0du9mvt6.bkt.clouddn.com&#x2F;images&#x2F;XLFormComplex&#x2F;xlform-complex-section.png">
<meta property="og:image" content="http:&#x2F;&#x2F;q0du9mvt6.bkt.clouddn.com&#x2F;images&#x2F;XLFormComplex&#x2F;xlform-complex-custom-section.png">
<meta property="og:image" content="http:&#x2F;&#x2F;q0du9mvt6.bkt.clouddn.com&#x2F;images&#x2F;XLFormComplex&#x2F;xlform-complex-custom-area.png">
<meta property="og:image" content="http:&#x2F;&#x2F;q0du9mvt6.bkt.clouddn.com&#x2F;images&#x2F;XLFormComplex&#x2F;xlform-complex-custom-area-done.gif">
<meta property="og:updated_time" content="2018-06-25T09:54:11.431Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http:&#x2F;&#x2F;q0du9mvt6.bkt.clouddn.com&#x2F;images&#x2F;XLFormComplex&#x2F;xlform-complex-section.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"hide","offset":12,"b2t":false,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":true,"transition":{"post_block":"perspectiveLeftIn","post_header":"fadeIn","post_body":"fadeIn","coll_header":"perspectiveLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://urm9ril.top/2017/06/25/XLForm-Complex-AreaPicker/"/>





  <title>XLForm 表单库的复杂使用 - 地址选择器 | ooops 的小站</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">ooops 的小站</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"><_`_></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/%20" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" target="_blank" rel="noopener" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://urm9ril.top/2017/06/25/XLForm-Complex-AreaPicker/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="张强">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="ooops 的小站">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">XLForm 表单库的复杂使用 - 地址选择器</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-25T19:28:46+08:00">
                2017-06-25
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/XLForm/" itemprop="url" rel="index">
                    <span itemprop="name">XLForm</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2017/06/25/XLForm-Complex-AreaPicker/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2017/06/25/XLForm-Complex-AreaPicker/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2017/06/25/XLForm-Complex-AreaPicker/" class="leancloud_visitors" data-flag-title="XLForm 表单库的复杂使用 - 地址选择器">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">热度&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
                 <span>℃</span>
             </span>
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  3,658
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  21
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <div class="note info"><p>这次来点特别的 </p></div>
<a id="more"></a>
<h2 id="组头的使用"><a href="#组头的使用" class="headerlink" title="组头的使用."></a>组头的使用.</h2><p>根据上一篇博文<a href="http://urm9ril.top/2017/05/02/XLForm-usage/">XLForm 表单库使用说明</a>的介绍,简单改造一下,先创建只有两个组头的表单.</p>
<p><code>ComplexConst</code> 常量文件</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 组头信息</span></span><br><span class="line"><span class="built_in">NSString</span> *<span class="keyword">const</span> kCompanyInfo = <span class="string">@"公司信息"</span>;</span><br><span class="line"><span class="built_in">NSString</span> *<span class="keyword">const</span> kContactInfo = <span class="string">@"联系人"</span>;</span><br></pre></td></tr></table></figure>
<p><code>ComplexFactory</code> 表单创建工厂类文件</p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="keyword">void</span>)initForm &#123;</span><br><span class="line">    XLFormSectionDescriptor * companySection = [XLFormSectionDescriptor formSectionWithTitle:kCompanyInfo];</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.form addFormSection:companySection];</span><br><span class="line">    </span><br><span class="line">    XLFormSectionDescriptor * contactSection = [XLFormSectionDescriptor formSectionWithTitle:kContactInfo];</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.form addFormSection:contactSection];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>效果如下:</p>
<img src="http://q0du9mvt6.bkt.clouddn.com/images/XLFormComplex/xlform-complex-section.png">
<h3 id="自定义组头"><a href="#自定义组头" class="headerlink" title="自定义组头"></a>自定义组头</h3><p>我们需要利用一下代理方法<br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="built_in">UIView</span> *)tableView:(<span class="built_in">UITableView</span> *)tableView viewForHeaderInSection:(<span class="built_in">NSInteger</span>)section</span><br><span class="line"><span class="comment">// 控制组头高度</span></span><br><span class="line">- (<span class="built_in">CGFloat</span>)tableView:(<span class="built_in">UITableView</span> *)tableView heightForHeaderInSection:(<span class="built_in">NSInteger</span>)section</span><br></pre></td></tr></table></figure></p>
<p>我们先来自定义一个组头视图 <code>SectionHeaderView</code></p>
<p><code>.h</code></p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">SectionHeaderView</span> : <span class="title">UIView</span></span></span><br><span class="line"></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithIndicatorColor:(<span class="built_in">UIColor</span> *)indicatorColor sectionTitle:(<span class="built_in">NSString</span> *)sectionTitle;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure>
<p><code>.m</code></p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">SectionHeaderView</span>()</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/** indicatorView - 指示器 */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">UIView</span>       *indicatorView;</span><br><span class="line"><span class="comment">/** titleV - 标题视图 */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">UILabel</span>      *titleLabel;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">SectionHeaderView</span> </span>&#123;</span><br><span class="line">    <span class="built_in">UIColor</span>     *_indicatorColor;</span><br><span class="line">    <span class="built_in">NSString</span>    *_sectionTitle;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">instancetype</span>)initWithIndicatorColor:(<span class="built_in">UIColor</span> *)indicatorColor sectionTitle:(<span class="built_in">NSString</span> *)sectionTitle &#123;</span><br><span class="line">    _indicatorColor = indicatorColor;</span><br><span class="line">    _sectionTitle = sectionTitle;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(<span class="keyword">self</span> = [<span class="keyword">super</span> initWithFrame:<span class="built_in">CGRectZero</span>]) &#123;</span><br><span class="line">        [<span class="keyword">self</span> setupUI];</span><br><span class="line">        [<span class="keyword">self</span> makeConstraint];</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">self</span>.indicatorView.backgroundColor = _indicatorColor;</span><br><span class="line">        <span class="keyword">self</span>.titleLabel.text = sectionTitle;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">self</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)setupUI &#123;</span><br><span class="line">    [<span class="keyword">self</span> addSubview:<span class="keyword">self</span>.indicatorView];</span><br><span class="line">    [<span class="keyword">self</span> addSubview:<span class="keyword">self</span>.titleLabel];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)makeConstraint &#123;</span><br><span class="line">    [<span class="keyword">self</span>.indicatorView mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.left.equalTo(<span class="keyword">self</span>).offset(<span class="number">20</span>);</span><br><span class="line">        make.centerY.equalTo(<span class="keyword">self</span>);</span><br><span class="line">        make.height.mas_equalTo(<span class="number">17</span>);</span><br><span class="line">        make.width.mas_equalTo(<span class="number">3</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.left.equalTo(<span class="keyword">self</span>.indicatorView.mas_right).offset(<span class="number">6</span>);</span><br><span class="line">        make.centerY.equalTo(<span class="keyword">self</span>.indicatorView);</span><br><span class="line">        make.right.equalTo(<span class="keyword">self</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIView</span> *)indicatorView &#123;</span><br><span class="line">    <span class="keyword">if</span>(_indicatorView) <span class="keyword">return</span> _indicatorView;</span><br><span class="line">    _indicatorView = [<span class="built_in">UIView</span> new];</span><br><span class="line">    <span class="keyword">return</span> _indicatorView;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UILabel</span> *)titleLabel &#123;</span><br><span class="line">    <span class="keyword">if</span>(_titleLabel) <span class="keyword">return</span> _titleLabel;</span><br><span class="line">    _titleLabel = [<span class="built_in">UILabel</span> new];</span><br><span class="line">    _titleLabel.textColor = [<span class="built_in">UIColor</span> orangeColor];</span><br><span class="line">    _titleLabel.font = [<span class="built_in">UIFont</span> systemFontOfSize:<span class="number">16</span>];</span><br><span class="line">    <span class="keyword">return</span> _titleLabel;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure>
<p><code>viewController.m</code> 中 </p>
<figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">ViewController</span> ()</span></span><br><span class="line"><span class="comment">/** 表头视图显示标题数组 */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSArray</span>       *sectionHeadViewTitleArray;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)viewDidLoad &#123;</span><br><span class="line">    [<span class="keyword">super</span> viewDidLoad];</span><br><span class="line">    <span class="keyword">self</span>.sectionHeadViewTitleArray = @[kCompanyInfo, kContactInfo];</span><br><span class="line">&#125;</span><br><span class="line">......</span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIView</span> *)tableView:(<span class="built_in">UITableView</span> *)tableView viewForHeaderInSection:(<span class="built_in">NSInteger</span>)section &#123;</span><br><span class="line">    <span class="built_in">NSString</span> *sectionTitle = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@"</span>,<span class="keyword">self</span>.sectionHeadViewTitleArray[section]];</span><br><span class="line">    SectionHeaderView *sectionHeadView = [[SectionHeaderView alloc] initWithIndicatorColor:HEXCOLOR(<span class="number">0xFF8A00</span>) sectionTitle:sectionTitle];</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> sectionHeadView;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">CGFloat</span>)tableView:(<span class="built_in">UITableView</span> *)tableView heightForHeaderInSection:(<span class="built_in">NSInteger</span>)section &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">30.</span>f;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>好了 跑一下看看吧.<br><img src="http://q0du9mvt6.bkt.clouddn.com/images/XLFormComplex/xlform-complex-custom-section.png"></p>
<h2 id="自定义地址选择器"><a href="#自定义地址选择器" class="headerlink" title="自定义地址选择器"></a>自定义地址选择器</h2><p>我们现在在第一组里面增加一个自定义的 <code>地址选择器</code> cell</p>
<p>回顾一下自定义 <code>cell</code> 的套路.</p>
<p><span id="inline-toc">1.</span>load</p>
<p>注册自定义的 <code>cell</code>.</p>
<p><span id="inline-toc">2.</span>configure</p>
<p>初始化一些 <code>cell</code> 配置信息.</p>
<p><span id="inline-toc">3.</span>update</p>
<p>更新 <code>XLFromRowDescriptor</code> 对象的 <code>value</code> 属性值.</p>
<p><code>ComplexAreaCell.h</code><br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#import <span class="meta-string">"XLFormBaseCell.h"</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">extern</span> <span class="built_in">NSString</span> * <span class="keyword">const</span> XLFormRowDescriporTypeComplexArea;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">ComplexAreaCell</span> : <span class="title">XLFormBaseCell</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">readonly</span>) <span class="built_in">UILabel</span>         *textLabel;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">readonly</span>) <span class="built_in">UITextField</span>     *textField;</span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">readonly</span>) <span class="built_in">UIImageView</span>     *accessorry;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure></p>
<p><code>ComplexAreaCell.m</code><br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#import <span class="meta-string">"ComplexAreaCell.h"</span></span></span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;XLForm/XLForm.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="built_in">NSString</span> * <span class="keyword">const</span> XLFormRowDescriporTypeComplexArea = <span class="string">@"XLFormRowDescriporTypeComplexArea"</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">ComplexAreaCell</span>()&lt;<span class="title">UIPickerViewDelegate</span>, <span class="title">UIPickerViewDataSource</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/** pickView */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">UIPickerView</span>      *pickerView;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">ComplexAreaCell</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">@synthesize</span> textLabel = _textLabel;</span><br><span class="line"><span class="keyword">@synthesize</span> textField = _textField;</span><br><span class="line"><span class="keyword">@synthesize</span> accessorry = _accessorry;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// 在主表单中加入一组Key Value 自定义的必须重写</span></span><br><span class="line">+ (<span class="keyword">void</span>)load &#123;</span><br><span class="line">    [XLFormViewController.cellClassesForRowDescriptorTypes setObject:[<span class="keyword">self</span> <span class="keyword">class</span>] forKey:XLFormRowDescriporTypeComplexArea];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIView</span> *)inputView &#123;</span><br><span class="line">    <span class="keyword">if</span> ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea])&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.pickerView;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> [<span class="keyword">super</span> inputView];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">BOOL</span>)formDescriptorCellCanBecomeFirstResponder &#123;</span><br><span class="line">    <span class="keyword">return</span> (!<span class="keyword">self</span>.rowDescriptor.isDisabled &amp;&amp; ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea]));</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">BOOL</span>)formDescriptorCellBecomeFirstResponder &#123;</span><br><span class="line">    <span class="keyword">return</span>  [<span class="keyword">self</span> becomeFirstResponder];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">BOOL</span>)canBecomeFirstResponder &#123;</span><br><span class="line">    <span class="keyword">if</span> ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea])&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">YES</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> [<span class="keyword">super</span> canBecomeFirstResponder];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#pragma mark - Properties</span></span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIPickerView</span> *)pickerView &#123;</span><br><span class="line">    <span class="keyword">if</span> (_pickerView) <span class="keyword">return</span> _pickerView;</span><br><span class="line">    _pickerView = [[<span class="built_in">UIPickerView</span> alloc] init];</span><br><span class="line">    _pickerView.delegate = <span class="keyword">self</span>;</span><br><span class="line">    _pickerView.dataSource = <span class="keyword">self</span>;</span><br><span class="line">    _pickerView.backgroundColor = HEXCOLOR(<span class="number">0xFFFFFF</span>);</span><br><span class="line">    <span class="keyword">return</span> _pickerView;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#pragma mark - XLFormDescriptorCell 配置cell</span></span><br><span class="line">- (<span class="keyword">void</span>)configure &#123;</span><br><span class="line">    [<span class="keyword">super</span> configure];</span><br><span class="line">    <span class="keyword">self</span>.currentProvinceId = <span class="keyword">self</span>.currentCityId = <span class="keyword">self</span>.currentAreaId = <span class="number">-1</span>;</span><br><span class="line">    [<span class="keyword">self</span> setSelectionStyle:<span class="built_in">UITableViewCellSelectionStyleNone</span>];</span><br><span class="line">    [<span class="keyword">self</span> setupUI];</span><br><span class="line">    [<span class="keyword">self</span> makeConstraint];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)setupUI &#123;</span><br><span class="line">    [<span class="keyword">self</span>.contentView addSubview:<span class="keyword">self</span>.textLabel];</span><br><span class="line">    [<span class="keyword">self</span>.contentView addSubview:<span class="keyword">self</span>.textField];</span><br><span class="line">    [<span class="keyword">self</span>.contentView addSubview:<span class="keyword">self</span>.accessorry];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)makeConstraint &#123;</span><br><span class="line">    [<span class="keyword">self</span>.textLabel mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.top.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">5</span>);</span><br><span class="line">        make.left.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">20</span>);</span><br><span class="line">        make.right.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">-20</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.textField mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.top.equalTo(<span class="keyword">self</span>.textLabel.mas_bottom).offset(<span class="number">10</span>);</span><br><span class="line">        make.left.equalTo(<span class="keyword">self</span>.textLabel);</span><br><span class="line">        make.right.equalTo(<span class="keyword">self</span>.textLabel);</span><br><span class="line">        make.height.mas_equalTo(<span class="number">44</span>);</span><br><span class="line">        make.bottom.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">-5</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">    [<span class="keyword">self</span>.accessorry mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.centerY.equalTo(<span class="keyword">self</span>.textField);</span><br><span class="line">        make.right.equalTo(<span class="keyword">self</span>.textField.mas_right).offset(<span class="number">-5</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)update &#123;</span><br><span class="line">    [<span class="keyword">super</span> update];</span><br><span class="line">    <span class="keyword">if</span> ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea])&#123;</span><br><span class="line">        <span class="keyword">self</span>.textField.autocorrectionType = <span class="built_in">UITextAutocorrectionTypeDefault</span>;</span><br><span class="line">        <span class="keyword">self</span>.textField.autocapitalizationType = <span class="built_in">UITextAutocapitalizationTypeSentences</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">self</span>.textField.text = <span class="keyword">self</span>.areaString ? <span class="keyword">self</span>.areaString : <span class="string">@"请选择"</span>;</span><br><span class="line">    [<span class="keyword">self</span>.textField setEnabled:!<span class="keyword">self</span>.rowDescriptor.isDisabled];</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">self</span>.textField.leftView = [[<span class="built_in">UIView</span> alloc] initWithFrame:<span class="built_in">CGRectMake</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">12</span>, <span class="keyword">self</span>.textField.frame.size.height)];</span><br><span class="line">    <span class="keyword">self</span>.textField.textColor = HEXCOLOR(<span class="number">0x000000</span>);</span><br><span class="line">    <span class="keyword">self</span>.textField.leftViewMode = <span class="built_in">UITextFieldViewModeAlways</span>;</span><br><span class="line">    <span class="keyword">self</span>.textField.layer.borderColor = HEXCOLOR(<span class="number">0xCCCCCC</span>).CGColor;</span><br><span class="line">    <span class="keyword">self</span>.textField.layer.borderWidth = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">self</span>.textField.font = [<span class="built_in">UIFont</span> systemFontOfSize:<span class="number">15</span>];</span><br><span class="line">    <span class="keyword">self</span>.textField.textAlignment = <span class="built_in">NSTextAlignmentCenter</span>;</span><br><span class="line">    <span class="keyword">self</span>.textField.enabled = <span class="literal">NO</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">NSInteger</span>)numberOfComponentsInPickerView:(<span class="built_in">UIPickerView</span>*)pickerView &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">3</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">NSInteger</span>)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView numberOfRowsInComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">3</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">NSString</span> *)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView titleForRow:(<span class="built_in">NSInteger</span>)row forComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">@"test"</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView didSelectRow:(<span class="built_in">NSInteger</span>)row inComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">self</span>.textField.text = <span class="string">@"test_a"</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">CGFloat</span>)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView rowHeightForComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">44</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIView</span> *)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView viewForRow:(<span class="built_in">NSInteger</span>)row forComponent:(<span class="built_in">NSInteger</span>)component reusingView:(<span class="keyword">nullable</span> <span class="built_in">UIView</span> *)view &#123;</span><br><span class="line">    <span class="comment">//设置分割线的颜色</span></span><br><span class="line">    <span class="keyword">for</span>(<span class="built_in">UIView</span> *singleLine <span class="keyword">in</span> pickerView.subviews) &#123;</span><br><span class="line">        <span class="keyword">if</span> (singleLine.frame.size.height &lt; <span class="number">1</span>) &#123;</span><br><span class="line">            singleLine.backgroundColor = HEXCOLOR(<span class="number">0xCCCCCC</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//设置文字的属性</span></span><br><span class="line">    <span class="built_in">UILabel</span> *genderLabel = [<span class="built_in">UILabel</span> new];</span><br><span class="line">    genderLabel.textAlignment = <span class="built_in">NSTextAlignmentCenter</span>;</span><br><span class="line">    genderLabel.text = [<span class="keyword">self</span> pickerView:pickerView titleForRow:row forComponent:component];</span><br><span class="line">    genderLabel.font = [<span class="built_in">UIFont</span> systemFontOfSize:<span class="number">20</span>];</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> genderLabel;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#pragma mark - Helpers</span></span><br><span class="line">- (<span class="built_in">NSInteger</span>)selectedIndex &#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">self</span>.rowDescriptor.value)&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">id</span> option <span class="keyword">in</span> <span class="keyword">self</span>.rowDescriptor.selectorOptions)&#123;</span><br><span class="line">            <span class="keyword">if</span> ([[option valueData] isEqual:[<span class="keyword">self</span>.rowDescriptor.value valueData]])&#123;</span><br><span class="line">                <span class="keyword">return</span> [<span class="keyword">self</span>.rowDescriptor.selectorOptions indexOfObject:option];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">-(<span class="built_in">UILabel</span> *)textLabel &#123;</span><br><span class="line">    <span class="keyword">if</span> (_textLabel) <span class="keyword">return</span> _textLabel;</span><br><span class="line">    _textLabel = [<span class="built_in">UILabel</span> autolayoutView];</span><br><span class="line">    _textLabel.textAlignment = <span class="built_in">NSTextAlignmentRight</span>;</span><br><span class="line">    <span class="keyword">return</span> _textLabel;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UITextField</span> *)textField &#123;</span><br><span class="line">    <span class="keyword">if</span>(_textField) <span class="keyword">return</span> _textField;</span><br><span class="line">    _textField = [<span class="built_in">UITextField</span> autolayoutView];</span><br><span class="line">    <span class="keyword">return</span> _textField;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIImageView</span> *)accessorry &#123;</span><br><span class="line">    <span class="keyword">if</span>(_accessorry) <span class="keyword">return</span> _accessorry;</span><br><span class="line">    _accessorry = [[<span class="built_in">UIImageView</span> alloc] initWithImage:[<span class="built_in">UIImage</span> imageNamed:<span class="string">@"pullDown"</span>]];</span><br><span class="line">    <span class="keyword">return</span> _accessorry;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#pragma mark - cell的点击触发事件</span></span><br><span class="line">-(<span class="keyword">void</span>)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)controller &#123;</span><br><span class="line">    <span class="keyword">self</span>.textField.text = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,provinceName,cityName,areaName];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure><br><code>ComplexFactory.m</code> 改造<br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="keyword">void</span>)initForm &#123;</span><br><span class="line">    XLFormSectionDescriptor * companySection = [XLFormSectionDescriptor formSectionWithTitle:kCompanyInfo];</span><br><span class="line">    </span><br><span class="line">    [companySection addFormRow:[<span class="keyword">self</span> rowFactoryWithWithTitle:<span class="string">@"* 地区"</span></span><br><span class="line">                                                         tag:kArea</span><br><span class="line">                                                    required:<span class="literal">YES</span></span><br><span class="line">                                                     rowType:XLFormRowDescriporTypeComplexArea</span><br><span class="line">                                                 placeholder:<span class="string">@"请选择"</span>]];</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.form addFormSection:companySection];</span><br><span class="line">    </span><br><span class="line">    XLFormSectionDescriptor * contactSection = [XLFormSectionDescriptor formSectionWithTitle:kContactInfo];</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.form addFormSection:contactSection];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>好了 ,再来看一下效果</p>
<img src="http://q0du9mvt6.bkt.clouddn.com/images/XLFormComplex/xlform-complex-custom-area.png">
<h3 id="地址数据"><a href="#地址数据" class="headerlink" title="地址数据"></a>地址数据</h3><p>用到了第三方 <code>YYModel</code></p>
<h4 id="模型编写"><a href="#模型编写" class="headerlink" title="模型编写"></a>模型编写</h4><p><code>IVModel.h</code><br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#import <span class="meta-string">&lt;Foundation/Foundation.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">IAreaModel</span> : <span class="title">NSObject</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">/** id */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSNumber</span>              *ID;</span><br><span class="line"><span class="comment">/** name */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span>               *name;</span><br><span class="line"><span class="comment">/** level */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span>              *level;</span><br><span class="line"><span class="comment">/** parent_id */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span>              *parent_id;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">ICityModel</span> : <span class="title">NSObject</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">/** id */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSNumber</span>                  *ID;</span><br><span class="line"><span class="comment">/** name */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span>                   *name;</span><br><span class="line"><span class="comment">/** level */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span>                  *level;</span><br><span class="line"><span class="comment">/** parent_id */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSString</span>                  *parent_id;</span><br><span class="line"><span class="comment">/** aereList */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSArray</span>&lt;IAreaModel *&gt;       *areaList;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure></p>
<p><code>IVModel.m</code><br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#import <span class="meta-string">"IVModel.h"</span></span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">IVModel</span> : <span class="title">NSObject</span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回容器类中的所需要存放的数据类型 (以 Class 或 Class Name 的形式)。</span></span><br><span class="line">+ (<span class="built_in">NSDictionary</span> *)modelContainerPropertyGenericClass &#123;</span><br><span class="line">    <span class="keyword">return</span> @&#123;<span class="string">@"citylist"</span> : [IModel <span class="keyword">class</span>]&#125;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">IModel</span> : <span class="title">NSObject</span></span></span><br><span class="line"></span><br><span class="line">+ (<span class="built_in">NSDictionary</span> *)modelCustomPropertyMapper &#123;</span><br><span class="line">    <span class="keyword">return</span> @&#123;<span class="string">@"ID"</span> : <span class="string">@"id"</span>&#125;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回容器类中的所需要存放的数据类型 (以 Class 或 Class Name 的形式)。</span></span><br><span class="line">+ (<span class="built_in">NSDictionary</span> *)modelContainerPropertyGenericClass &#123;</span><br><span class="line">    <span class="keyword">return</span> @&#123;<span class="string">@"areaList"</span> : [ICityModel <span class="keyword">class</span>]&#125;;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">IAreaModel</span></span></span><br><span class="line"></span><br><span class="line">+ (<span class="built_in">NSDictionary</span> *)modelCustomPropertyMapper &#123;</span><br><span class="line">    <span class="keyword">return</span> @&#123;<span class="string">@"ID"</span> : <span class="string">@"id"</span>&#125;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">ICityModel</span></span></span><br><span class="line"></span><br><span class="line">+ (<span class="built_in">NSDictionary</span> *)modelCustomPropertyMapper &#123;</span><br><span class="line">    <span class="keyword">return</span> @&#123;<span class="string">@"ID"</span> : <span class="string">@"id"</span>&#125;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 返回容器类中的所需要存放的数据类型 (以 Class 或 Class Name 的形式)。</span></span><br><span class="line">+ (<span class="built_in">NSDictionary</span> *)modelContainerPropertyGenericClass &#123;</span><br><span class="line">    <span class="keyword">return</span> @&#123;<span class="string">@"areaList"</span> : [IAreaModel <span class="keyword">class</span>]&#125;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure></p>
<h4 id="数据文件及解析方法"><a href="#数据文件及解析方法" class="headerlink" title="数据文件及解析方法"></a>数据文件及解析方法</h4><p><code>viewController</code> 中添加获取数据的方法.<br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">- (<span class="keyword">void</span>)loadData &#123;</span><br><span class="line">    <span class="built_in">NSString</span> *str = [[<span class="built_in">NSBundle</span> mainBundle] pathForResource:<span class="string">@"json"</span> ofType:<span class="string">@"txt"</span>];</span><br><span class="line">    <span class="built_in">NSDictionary</span> *result = [<span class="built_in">NSJSONSerialization</span> JSONObjectWithData:[<span class="built_in">NSData</span> dataWithContentsOfFile:str] options:<span class="number">0</span> error:<span class="literal">NULL</span>];</span><br><span class="line">    <span class="keyword">self</span>.factory.provinceModel = [IVModel yy_modelWithDictionary:result];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h4 id="自定义cell的改造"><a href="#自定义cell的改造" class="headerlink" title="自定义cell的改造"></a>自定义cell的改造</h4><p><code>ComplexAreaCell.m</code><br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#import <span class="meta-string">"ComplexAreaCell.h"</span></span></span><br><span class="line"><span class="meta">#import <span class="meta-string">&lt;XLForm/XLForm.h&gt;</span></span></span><br><span class="line"><span class="meta">#import <span class="meta-string">"IVModel.h"</span></span></span><br><span class="line"></span><br><span class="line"><span class="built_in">NSString</span> * <span class="keyword">const</span> XLFormRowDescriporTypeComplexArea = <span class="string">@"XLFormRowDescriporTypeComplexArea"</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@interface</span> <span class="title">ComplexAreaCell</span>()&lt;<span class="title">UIPickerViewDelegate</span>, <span class="title">UIPickerViewDataSource</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/** pickView */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">UIPickerView</span>      *pickerView;</span><br><span class="line"><span class="comment">/** ids */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">copy</span>) <span class="built_in">NSString</span> *areaString;</span><br><span class="line"><span class="comment">//数据模型</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) IVModel           *provinceModel;</span><br><span class="line"><span class="comment">/** province模型数组 */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSArray</span>&lt;IModel *&gt;       *provinceModelArray;</span><br><span class="line"><span class="comment">/** city模型数组 */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSArray</span>&lt;ICityModel *&gt;       *cityModelArray;</span><br><span class="line"><span class="comment">/** area模型数组 */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) <span class="built_in">NSArray</span>&lt;IAreaModel *&gt;       *areaModelArray;</span><br><span class="line"><span class="comment">/** province ID */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>,<span class="keyword">assign</span>) <span class="built_in">NSInteger</span> currentProvinceId;</span><br><span class="line"><span class="comment">/** city ID */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>,<span class="keyword">assign</span>) <span class="built_in">NSInteger</span> currentCityId;</span><br><span class="line"><span class="comment">/** area ID */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>,<span class="keyword">assign</span>) <span class="built_in">NSInteger</span> currentAreaId;</span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">@implementation</span> <span class="title">ComplexAreaCell</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">@synthesize</span> textLabel = _textLabel;</span><br><span class="line"><span class="keyword">@synthesize</span> textField = _textField;</span><br><span class="line"><span class="keyword">@synthesize</span> accessorry = _accessorry;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// 在主表单中加入一组Key Value 自定义的必须重写</span></span><br><span class="line">+ (<span class="keyword">void</span>)load &#123;</span><br><span class="line">    [XLFormViewController.cellClassesForRowDescriptorTypes setObject:[<span class="keyword">self</span> <span class="keyword">class</span>] forKey:XLFormRowDescriporTypeComplexArea];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIView</span> *)inputView &#123;</span><br><span class="line">    <span class="keyword">if</span> ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea])&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.pickerView;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> [<span class="keyword">super</span> inputView];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">BOOL</span>)formDescriptorCellCanBecomeFirstResponder &#123;</span><br><span class="line">    <span class="keyword">return</span> (!<span class="keyword">self</span>.rowDescriptor.isDisabled &amp;&amp; ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea]));</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">BOOL</span>)formDescriptorCellBecomeFirstResponder &#123;</span><br><span class="line">    <span class="keyword">return</span>  [<span class="keyword">self</span> becomeFirstResponder];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">BOOL</span>)canBecomeFirstResponder &#123;</span><br><span class="line">    <span class="keyword">if</span> ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea])&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">YES</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> [<span class="keyword">super</span> canBecomeFirstResponder];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#pragma mark - Properties</span></span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIPickerView</span> *)pickerView &#123;</span><br><span class="line">    <span class="keyword">if</span> (_pickerView) <span class="keyword">return</span> _pickerView;</span><br><span class="line">    _pickerView = [[<span class="built_in">UIPickerView</span> alloc] init];</span><br><span class="line">    _pickerView.delegate = <span class="keyword">self</span>;</span><br><span class="line">    _pickerView.dataSource = <span class="keyword">self</span>;</span><br><span class="line">    _pickerView.backgroundColor = HEXCOLOR(<span class="number">0xFFFFFF</span>);</span><br><span class="line">    <span class="keyword">return</span> _pickerView;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#pragma mark - XLFormDescriptorCell 配置cell</span></span><br><span class="line">- (<span class="keyword">void</span>)configure &#123;</span><br><span class="line">    [<span class="keyword">super</span> configure];</span><br><span class="line">    <span class="keyword">self</span>.currentProvinceId = <span class="keyword">self</span>.currentCityId = <span class="keyword">self</span>.currentAreaId = <span class="number">-1</span>;</span><br><span class="line">    [<span class="keyword">self</span> setSelectionStyle:<span class="built_in">UITableViewCellSelectionStyleNone</span>];</span><br><span class="line">    [<span class="keyword">self</span> setupUI];</span><br><span class="line">    [<span class="keyword">self</span> makeConstraint];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)setupUI &#123;</span><br><span class="line">    [<span class="keyword">self</span>.contentView addSubview:<span class="keyword">self</span>.textLabel];</span><br><span class="line">    [<span class="keyword">self</span>.contentView addSubview:<span class="keyword">self</span>.textField];</span><br><span class="line">    [<span class="keyword">self</span>.contentView addSubview:<span class="keyword">self</span>.accessorry];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)makeConstraint &#123;</span><br><span class="line">    [<span class="keyword">self</span>.textLabel mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.top.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">5</span>);</span><br><span class="line">        make.left.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">20</span>);</span><br><span class="line">        make.right.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">-20</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">    </span><br><span class="line">    [<span class="keyword">self</span>.textField mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.top.equalTo(<span class="keyword">self</span>.textLabel.mas_bottom).offset(<span class="number">10</span>);</span><br><span class="line">        make.left.equalTo(<span class="keyword">self</span>.textLabel);</span><br><span class="line">        make.right.equalTo(<span class="keyword">self</span>.textLabel);</span><br><span class="line">        make.height.mas_equalTo(<span class="number">44</span>);</span><br><span class="line">        make.bottom.equalTo(<span class="keyword">self</span>.contentView).offset(<span class="number">-5</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">    [<span class="keyword">self</span>.accessorry mas_makeConstraints:^(MASConstraintMaker *make) &#123;</span><br><span class="line">        make.centerY.equalTo(<span class="keyword">self</span>.textField);</span><br><span class="line">        make.right.equalTo(<span class="keyword">self</span>.textField.mas_right).offset(<span class="number">-5</span>);</span><br><span class="line">    &#125;];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)titleHighLight &#123;</span><br><span class="line">    <span class="built_in">NSString</span> *title = <span class="keyword">self</span>.rowDescriptor.title;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">self</span>.textLabel.font = [<span class="built_in">UIFont</span> fontWithName:<span class="string">@"HelveticaNeue"</span> size:<span class="number">12</span>];</span><br><span class="line">    <span class="built_in">NSMutableAttributedString</span> *str = [[<span class="built_in">NSMutableAttributedString</span> alloc] initWithString:[<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@"</span>,title]];</span><br><span class="line">    <span class="built_in">NSMutableParagraphStyle</span> *paragraphStyle = [[<span class="built_in">NSMutableParagraphStyle</span> alloc] init];</span><br><span class="line">    <span class="comment">// 首行缩进</span></span><br><span class="line">    paragraphStyle.alignment = <span class="built_in">NSTextAlignmentLeft</span>;</span><br><span class="line">    <span class="keyword">if</span>([title rangeOfString:<span class="string">@"*"</span>].location != <span class="built_in">NSNotFound</span>) &#123;</span><br><span class="line">        [str addAttribute:<span class="built_in">NSForegroundColorAttributeName</span> value:[<span class="built_in">UIColor</span> redColor] range:<span class="built_in">NSMakeRange</span>(<span class="number">0</span>,<span class="number">1</span>)];</span><br><span class="line">    &#125;</span><br><span class="line">    [str addAttribute:<span class="built_in">NSParagraphStyleAttributeName</span> value:paragraphStyle range:<span class="built_in">NSMakeRange</span>(<span class="number">0</span>, [title length])];</span><br><span class="line">    [str addAttribute:<span class="built_in">NSFontAttributeName</span> value:[<span class="built_in">UIFont</span> fontWithName:<span class="string">@"HelveticaNeue"</span> size:<span class="number">12</span>] range:<span class="built_in">NSMakeRange</span>(<span class="number">0</span>, [title length])];</span><br><span class="line">    <span class="keyword">self</span>.textLabel.attributedText = str;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)update &#123;</span><br><span class="line">    [<span class="keyword">super</span> update];</span><br><span class="line">    <span class="keyword">if</span> ([<span class="keyword">self</span>.rowDescriptor.rowType isEqualToString:XLFormRowDescriporTypeComplexArea])&#123;</span><br><span class="line">        <span class="keyword">self</span>.textField.autocorrectionType = <span class="built_in">UITextAutocorrectionTypeDefault</span>;</span><br><span class="line">        <span class="keyword">self</span>.textField.autocapitalizationType = <span class="built_in">UITextAutocapitalizationTypeSentences</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    [<span class="keyword">self</span> titleHighLight];</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">self</span>.textField.text = <span class="keyword">self</span>.areaString ? <span class="keyword">self</span>.areaString : <span class="string">@"请选择"</span>;</span><br><span class="line">    [<span class="keyword">self</span>.textField setEnabled:!<span class="keyword">self</span>.rowDescriptor.isDisabled];</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">self</span>.textField.leftView = [[<span class="built_in">UIView</span> alloc] initWithFrame:<span class="built_in">CGRectMake</span>(<span class="number">0</span>, <span class="number">0</span>, <span class="number">12</span>, <span class="keyword">self</span>.textField.frame.size.height)];</span><br><span class="line">    <span class="keyword">self</span>.textField.textColor = HEXCOLOR(<span class="number">0x000000</span>);</span><br><span class="line">    <span class="keyword">self</span>.textField.leftViewMode = <span class="built_in">UITextFieldViewModeAlways</span>;</span><br><span class="line">    <span class="keyword">self</span>.textField.layer.borderColor = HEXCOLOR(<span class="number">0xCCCCCC</span>).CGColor;</span><br><span class="line">    <span class="keyword">self</span>.textField.layer.borderWidth = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">self</span>.textField.font = [<span class="built_in">UIFont</span> systemFontOfSize:<span class="number">15</span>];</span><br><span class="line">    <span class="keyword">self</span>.textField.textAlignment = <span class="built_in">NSTextAlignmentCenter</span>;</span><br><span class="line">    <span class="keyword">self</span>.textField.enabled = <span class="literal">NO</span>;</span><br><span class="line">    [<span class="keyword">self</span> preSelectedValue];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> 设置每次应该默认选中的项</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">- (<span class="keyword">void</span>)preSelectedValue &#123;</span><br><span class="line">    <span class="keyword">if</span>(!<span class="keyword">self</span>.rowDescriptor.value) <span class="keyword">return</span>;</span><br><span class="line">    <span class="built_in">NSString</span> __block *provinceName,__block *cityName,__block *areaName ;</span><br><span class="line">    <span class="built_in">NSString</span> *ids = <span class="literal">nil</span>;</span><br><span class="line">    <span class="keyword">if</span>([<span class="keyword">self</span>.rowDescriptor.value isKindOfClass:[XLFormOptionsObject <span class="keyword">class</span>]]) &#123;</span><br><span class="line">        ids = [<span class="keyword">self</span>.rowDescriptor.value formValue];</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        ids = <span class="keyword">self</span>.rowDescriptor.value;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(!ids) <span class="keyword">return</span>;</span><br><span class="line">    <span class="built_in">NSArray</span> *idss = [ids componentsSeparatedByString:<span class="string">@"-"</span>];</span><br><span class="line">    <span class="keyword">if</span>(!idss) <span class="keyword">return</span>;</span><br><span class="line">    <span class="keyword">if</span>(!<span class="keyword">self</span>.provinceModelArray) <span class="keyword">return</span>;</span><br><span class="line">    [<span class="keyword">self</span>.provinceModelArray enumerateObjectsUsingBlock:^(IModel * _Nonnull obj, <span class="built_in">NSUInteger</span> idx, <span class="built_in">BOOL</span> * _Nonnull stop) &#123;</span><br><span class="line">        <span class="keyword">if</span>([obj.ID integerValue] == [idss[<span class="number">0</span>] integerValue]) &#123;</span><br><span class="line">            <span class="keyword">self</span>.currentProvinceId = idx;</span><br><span class="line">            provinceName = obj.name;</span><br><span class="line">            *stop = <span class="literal">YES</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        [obj.areaList enumerateObjectsUsingBlock:^(ICityModel * _Nonnull obj, <span class="built_in">NSUInteger</span> idx, <span class="built_in">BOOL</span> * _Nonnull stop) &#123;</span><br><span class="line">            <span class="keyword">if</span>([obj.ID integerValue] == [idss[<span class="number">1</span>] integerValue]) &#123;</span><br><span class="line">                <span class="keyword">self</span>.currentCityId = idx;</span><br><span class="line">                cityName = obj.name;</span><br><span class="line">                *stop = <span class="literal">YES</span>;</span><br><span class="line">            &#125;</span><br><span class="line">            [obj.areaList enumerateObjectsUsingBlock:^(IAreaModel * _Nonnull obj, <span class="built_in">NSUInteger</span> idx, <span class="built_in">BOOL</span> * _Nonnull stop) &#123;</span><br><span class="line">                <span class="keyword">if</span>([obj.ID integerValue] == [idss[<span class="number">2</span>] integerValue]) &#123;</span><br><span class="line">                    <span class="keyword">self</span>.currentAreaId = idx;</span><br><span class="line">                    areaName = obj.name;</span><br><span class="line">                    *stop = <span class="literal">YES</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;];</span><br><span class="line">        &#125;];</span><br><span class="line">    &#125;];</span><br><span class="line">    <span class="keyword">self</span>.textField.text = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,provinceName,cityName,areaName];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">NSInteger</span>)numberOfComponentsInPickerView:(<span class="built_in">UIPickerView</span>*)pickerView &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">3</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">NSInteger</span>)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView numberOfRowsInComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="number">0</span> == component) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.provinceModelArray.count;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (<span class="number">1</span> == component) &#123;</span><br><span class="line">        <span class="built_in">NSInteger</span> rowProvince = [pickerView selectedRowInComponent:<span class="number">0</span>];</span><br><span class="line">        <span class="keyword">self</span>.cityModelArray = <span class="keyword">self</span>.provinceModelArray[rowProvince].areaList;</span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">self</span>.currentProvinceId &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">self</span>.cityModelArray = <span class="keyword">self</span>.provinceModelArray[<span class="keyword">self</span>.currentProvinceId].areaList;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.cityModelArray.count &gt; <span class="number">0</span> ? <span class="keyword">self</span>.cityModelArray.count : <span class="number">1</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="built_in">NSInteger</span> rowProvince1 = [pickerView selectedRowInComponent:<span class="number">1</span>];</span><br><span class="line">        <span class="keyword">self</span>.areaModelArray = <span class="keyword">self</span>.cityModelArray[rowProvince1].areaList;</span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">self</span>.currentCityId &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">self</span>.areaModelArray = <span class="keyword">self</span>.cityModelArray[<span class="keyword">self</span>.currentCityId].areaList;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.areaModelArray.count &gt; <span class="number">0</span> ? <span class="keyword">self</span>.areaModelArray.count : <span class="number">1</span>;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">NSString</span> *)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView titleForRow:(<span class="built_in">NSInteger</span>)row forComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="number">0</span> == component) &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.provinceModelArray[row].name;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(<span class="number">1</span> == component)&#123;</span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">self</span>.cityModelArray.count == <span class="number">1</span>) <span class="keyword">return</span> <span class="keyword">self</span>.cityModelArray[<span class="number">0</span>].name;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.cityModelArray[row].name;</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="keyword">if</span>(<span class="keyword">self</span>.areaModelArray.count == <span class="number">1</span>) <span class="keyword">return</span> <span class="keyword">self</span>.areaModelArray[<span class="number">0</span>].name;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">self</span>.areaModelArray[row].name;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="keyword">void</span>)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView didSelectRow:(<span class="built_in">NSInteger</span>)row inComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">self</span>.currentProvinceId = [<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">0</span>];</span><br><span class="line">    <span class="keyword">self</span>.currentCityId = [<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">1</span>];</span><br><span class="line">    <span class="keyword">self</span>.currentAreaId = [<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">2</span>];</span><br><span class="line">    <span class="keyword">switch</span> (component) &#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">0</span>:</span><br><span class="line">            <span class="keyword">self</span>.currentCityId = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">self</span>.cityModelArray = <span class="literal">nil</span>;</span><br><span class="line">            <span class="keyword">self</span>.cityModelArray = <span class="keyword">self</span>.provinceModelArray[<span class="keyword">self</span>.currentProvinceId].areaList;</span><br><span class="line">            [<span class="keyword">self</span>.pickerView reloadComponent:<span class="number">1</span>];</span><br><span class="line">            [<span class="keyword">self</span>.pickerView reloadComponent:<span class="number">2</span>];</span><br><span class="line">            <span class="comment">//让刷新后的第一和二 个滚轮重新回到第一行</span></span><br><span class="line">            [<span class="keyword">self</span>.pickerView selectRow:<span class="number">0</span> inComponent:<span class="number">1</span> animated:<span class="literal">YES</span>];</span><br><span class="line">            [<span class="keyword">self</span>.pickerView selectRow:<span class="number">0</span> inComponent:<span class="number">2</span> animated:<span class="literal">YES</span>];</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">            <span class="keyword">self</span>.currentAreaId = <span class="number">0</span>;</span><br><span class="line">            <span class="keyword">self</span>.areaModelArray = <span class="literal">nil</span>;</span><br><span class="line">            <span class="keyword">self</span>.areaModelArray = <span class="keyword">self</span>.cityModelArray[<span class="keyword">self</span>.currentCityId].areaList;</span><br><span class="line">            [<span class="keyword">self</span>.pickerView reloadComponent:<span class="number">2</span>];</span><br><span class="line">            <span class="comment">//让刷新后的第二个滚轮重新回到第一行</span></span><br><span class="line">            [<span class="keyword">self</span>.pickerView selectRow:<span class="number">0</span> inComponent:<span class="number">2</span> animated:<span class="literal">YES</span>];</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 获取城市ID</span></span><br><span class="line">    <span class="built_in">NSString</span> *procinveID = [<span class="keyword">self</span>.provinceModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">0</span>]].ID stringValue];</span><br><span class="line">    <span class="built_in">NSString</span> *cityID = [<span class="keyword">self</span>.cityModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">1</span>]].ID stringValue];</span><br><span class="line">    <span class="built_in">NSString</span> *areaID = [<span class="keyword">self</span>.areaModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">2</span>]].ID stringValue];</span><br><span class="line">    <span class="comment">// 记录当前选中行</span></span><br><span class="line">    <span class="keyword">self</span>.currentProvinceId = [<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">0</span>];</span><br><span class="line">    <span class="keyword">self</span>.currentCityId = [<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">1</span>];</span><br><span class="line">    <span class="keyword">self</span>.currentAreaId = [<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">2</span>];</span><br><span class="line">    <span class="comment">// 获取城市名字</span></span><br><span class="line">    <span class="built_in">NSString</span> *provinceName = <span class="keyword">self</span>.provinceModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">0</span>]].name;</span><br><span class="line">    <span class="built_in">NSString</span> *cityName = <span class="keyword">self</span>.cityModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">1</span>]].name;</span><br><span class="line">    <span class="built_in">NSString</span> *areaName = <span class="keyword">self</span>.areaModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">2</span>]].name;</span><br><span class="line">    <span class="keyword">self</span>.rowDescriptor.value = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,procinveID,cityID,areaID];</span><br><span class="line">    <span class="keyword">self</span>.textField.text = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,provinceName,cityName,areaName];</span><br><span class="line">    <span class="keyword">self</span>.areaString = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,provinceName,cityName,areaName];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">CGFloat</span>)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView rowHeightForComponent:(<span class="built_in">NSInteger</span>)component &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">44</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIView</span> *)pickerView:(<span class="built_in">UIPickerView</span> *)pickerView viewForRow:(<span class="built_in">NSInteger</span>)row forComponent:(<span class="built_in">NSInteger</span>)component reusingView:(<span class="keyword">nullable</span> <span class="built_in">UIView</span> *)view &#123;</span><br><span class="line">    <span class="comment">//设置分割线的颜色</span></span><br><span class="line">    <span class="keyword">for</span>(<span class="built_in">UIView</span> *singleLine <span class="keyword">in</span> pickerView.subviews) &#123;</span><br><span class="line">        <span class="keyword">if</span> (singleLine.frame.size.height &lt; <span class="number">1</span>) &#123;</span><br><span class="line">            singleLine.backgroundColor = HEXCOLOR(<span class="number">0xCCCCCC</span>);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//设置文字的属性</span></span><br><span class="line">    <span class="built_in">UILabel</span> *genderLabel = [<span class="built_in">UILabel</span> new];</span><br><span class="line">    genderLabel.textAlignment = <span class="built_in">NSTextAlignmentCenter</span>;</span><br><span class="line">    genderLabel.text = [<span class="keyword">self</span> pickerView:pickerView titleForRow:row forComponent:component];</span><br><span class="line">    genderLabel.font = [<span class="built_in">UIFont</span> systemFontOfSize:<span class="number">20</span>];</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">return</span> genderLabel;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#pragma mark - Helpers</span></span><br><span class="line">- (<span class="built_in">NSInteger</span>)selectedIndex &#123;</span><br><span class="line">    <span class="keyword">if</span> (<span class="keyword">self</span>.rowDescriptor.value)&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">id</span> option <span class="keyword">in</span> <span class="keyword">self</span>.rowDescriptor.selectorOptions)&#123;</span><br><span class="line">            <span class="keyword">if</span> ([[option valueData] isEqual:[<span class="keyword">self</span>.rowDescriptor.value valueData]])&#123;</span><br><span class="line">                <span class="keyword">return</span> [<span class="keyword">self</span>.rowDescriptor.selectorOptions indexOfObject:option];</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-(<span class="built_in">UILabel</span> *)textLabel &#123;</span><br><span class="line">    <span class="keyword">if</span> (_textLabel) <span class="keyword">return</span> _textLabel;</span><br><span class="line">    _textLabel = [<span class="built_in">UILabel</span> autolayoutView];</span><br><span class="line">    _textLabel.textAlignment = <span class="built_in">NSTextAlignmentRight</span>;</span><br><span class="line">    <span class="keyword">return</span> _textLabel;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UITextField</span> *)textField &#123;</span><br><span class="line">    <span class="keyword">if</span>(_textField) <span class="keyword">return</span> _textField;</span><br><span class="line">    _textField = [<span class="built_in">UITextField</span> autolayoutView];</span><br><span class="line">    <span class="keyword">return</span> _textField;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">- (<span class="built_in">UIImageView</span> *)accessorry &#123;</span><br><span class="line">    <span class="keyword">if</span>(_accessorry) <span class="keyword">return</span> _accessorry;</span><br><span class="line">    _accessorry = [[<span class="built_in">UIImageView</span> alloc] initWithImage:[<span class="built_in">UIImage</span> imageNamed:<span class="string">@"pullDown"</span>]];</span><br><span class="line">    <span class="keyword">return</span> _accessorry;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">#pragma mark - 数据设置</span></span><br><span class="line">- (<span class="keyword">void</span>)setProvinceModel:(IVModel *)provinceModel &#123;</span><br><span class="line">    _provinceModel = provinceModel;</span><br><span class="line">    <span class="keyword">self</span>.provinceModelArray = _provinceModel.citylist;</span><br><span class="line">    [<span class="keyword">self</span>.pickerView reloadAllComponents];</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#pragma mark - cell的点击触发事件</span></span><br><span class="line">-(<span class="keyword">void</span>)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)controller &#123;</span><br><span class="line">    <span class="built_in">NSString</span> *provinceName, *cityName, *areaName ;</span><br><span class="line">    <span class="keyword">if</span>(<span class="keyword">self</span>.currentProvinceId &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">        [<span class="keyword">self</span>.pickerView selectRow:<span class="keyword">self</span>.currentProvinceId inComponent:<span class="number">0</span> animated:<span class="literal">NO</span>];</span><br><span class="line">        provinceName = <span class="keyword">self</span>.provinceModelArray[<span class="keyword">self</span>.currentProvinceId].name;</span><br><span class="line">        <span class="keyword">self</span>.cityModelArray = <span class="keyword">self</span>.provinceModelArray[<span class="keyword">self</span>.currentProvinceId].areaList;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(<span class="keyword">self</span>.currentCityId &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">        [<span class="keyword">self</span>.pickerView selectRow:<span class="keyword">self</span>.currentCityId inComponent:<span class="number">1</span> animated:<span class="literal">NO</span>];</span><br><span class="line">        cityName = <span class="keyword">self</span>.cityModelArray[<span class="keyword">self</span>.currentCityId].name;</span><br><span class="line">        <span class="keyword">self</span>.areaModelArray = <span class="keyword">self</span>.cityModelArray[<span class="keyword">self</span>.currentCityId].areaList;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(<span class="keyword">self</span>.currentAreaId &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">        [<span class="keyword">self</span>.pickerView selectRow:<span class="keyword">self</span>.currentAreaId inComponent:<span class="number">2</span> animated:<span class="literal">NO</span>];</span><br><span class="line">        areaName = <span class="keyword">self</span>.areaModelArray[<span class="keyword">self</span>.currentAreaId].name;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(!provinceName &amp;&amp; !cityName &amp;&amp; !areaName) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 为了第一次点击cell的时候设置value</span></span><br><span class="line">    <span class="built_in">NSString</span> *procinveID = [<span class="keyword">self</span>.provinceModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">0</span>]].ID stringValue];</span><br><span class="line">    <span class="built_in">NSString</span> *cityID = [<span class="keyword">self</span>.cityModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">1</span>]].ID stringValue];</span><br><span class="line">    <span class="built_in">NSString</span> *areaID = [<span class="keyword">self</span>.areaModelArray[[<span class="keyword">self</span>.pickerView selectedRowInComponent:<span class="number">2</span>]].ID stringValue];</span><br><span class="line">    <span class="keyword">self</span>.rowDescriptor.value = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,procinveID,cityID,areaID];</span><br><span class="line"></span><br><span class="line">    <span class="keyword">self</span>.textField.text = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,provinceName,cityName,areaName];</span><br><span class="line">    <span class="keyword">self</span>.areaString = [<span class="built_in">NSString</span> stringWithFormat:<span class="string">@"%@-%@-%@"</span>,provinceName,cityName,areaName];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">@end</span></span><br></pre></td></tr></table></figure></p>
<h4 id="表单创建类-ComplexFactory"><a href="#表单创建类-ComplexFactory" class="headerlink" title="表单创建类 ComplexFactory"></a>表单创建类 ComplexFactory</h4><p><code>ComplexFactory.h</code> 中增加记录地址数据的属性<br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/** IVModel 城市联动数据模型 */</span></span><br><span class="line"><span class="keyword">@property</span> (<span class="keyword">nonatomic</span>, <span class="keyword">strong</span>) IVModel                       *provinceModel;</span><br></pre></td></tr></table></figure><br><code>ComplexFactory.m</code> 中通过 <code>kvc</code> 赋值 <code>provinceModel</code> 地址数据.<br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">- (XLFormRowDescriptor *)rowFactoryWithWithTitle:(<span class="built_in">NSString</span> *)headerTitle tag:(<span class="built_in">NSString</span> *)tag required:(<span class="built_in">BOOL</span>)required rowType:(<span class="built_in">NSString</span> *)rowType placeholder:(<span class="built_in">NSString</span> *)placeholder &#123;</span><br><span class="line">    XLFormRowDescriptor *row;</span><br><span class="line">    row = [XLFormRowDescriptor formRowDescriptorWithTag:tag rowType:rowType];</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">if</span>(tag == kArea) &#123;</span><br><span class="line">        [row.cellConfig setValue:<span class="keyword">self</span>.provinceModel forKey:<span class="string">@"provinceModel"</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(required) &#123;</span><br><span class="line">        row.requireMsg = <span class="string">@"带*为必填!"</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    row.required = required;</span><br><span class="line">    row.title = headerTitle;</span><br><span class="line">    row.height = <span class="built_in">UITableViewAutomaticDimension</span>;</span><br><span class="line">    <span class="keyword">return</span> row;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h3 id="数据验证器"><a href="#数据验证器" class="headerlink" title="数据验证器"></a>数据验证器</h3><p><code>ComplexRegValidator.m</code> 的验证方法.<br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">+ (XLFormValidator *)areaValidator &#123;</span><br><span class="line">    <span class="keyword">return</span> [XLFormRegexValidator formRegexValidatorWithMsg:<span class="built_in">NSLocalizedString</span>(<span class="string">@"请选择地址"</span>, <span class="literal">nil</span>) regex:<span class="string">@"^((?!请选择).)*$"</span>];</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p><code>ComplexFactory.m</code><br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">......</span><br><span class="line">[row addValidator:[ComplexRegValidator areaValidator]];</span><br><span class="line">......</span><br></pre></td></tr></table></figure></p>
<p><code>ComplexValidator.m</code><br><figure class="highlight objc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">......</span><br><span class="line"><span class="keyword">if</span> ([validationStatus.rowDescriptor.tag isEqualToString:kArea] &amp;&amp; !validationStatus.isValid) &#123;</span><br><span class="line">    *stop = <span class="literal">YES</span>;</span><br><span class="line">    <span class="comment">// show hud ....</span></span><br><span class="line"> &#125;</span><br><span class="line">......</span><br></pre></td></tr></table></figure></p>
<p>好了,结束了.来看一下 <code>gif</code></p>
<img src="http://q0du9mvt6.bkt.clouddn.com/images/XLFormComplex/xlform-complex-custom-area-done.gif">
<p>补上最想要的 <a href="git@github.com:urm9ril/XLFormComplex.git">Demo</a> </p>

      
    </div>
    
    
    

    

    <div>
      
        
<div class="my_post_copyright">
  <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>
  
  <!-- JS库 sweetalert 可修改路径 -->
  <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
  <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
  <p><span>本文标题:</span><a href="/2017/06/25/XLForm-Complex-AreaPicker/">XLForm 表单库的复杂使用 - 地址选择器</a></p>
  <p><span>文章作者:</span><a href="/" title="访问 张强 的个人博客">张强</a></p>
  <p><span>发布时间:</span>2017年06月25日 - 19:06</p>
  <p><span>最后更新:</span>2018年06月25日 - 17:06</p>
  <p><span>原始链接:</span><a href="/2017/06/25/XLForm-Complex-AreaPicker/" title="XLForm 表单库的复杂使用 - 地址选择器">http://urm9ril.top/2017/06/25/XLForm-Complex-AreaPicker/</a>
    <span class="copy-path"  title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="http://urm9ril.top/2017/06/25/XLForm-Complex-AreaPicker/"  aria-label="复制成功！"></i></span>
  </p>
  <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
</div>
<script> 
    var clipboard = new Clipboard('.fa-clipboard');
      $(".fa-clipboard").click(function(){
      clipboard.on('success', function(){
        swal({   
          title: "",   
          text: '复制成功',
          icon: "success", 
          showConfirmButton: true
          });
        });
    });  
</script>

      
    </div>

    

    

    

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束  <i class="fa-window-minimize"></i>  ß感谢您的阅读-------------</div>
    
</div>
      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/XLForm/" <i class="fa fa-tags"></i>XLForm</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/06/13/qiniuyun/" rel="next" title="Hexo图床之七牛云">
                <i class="fa fa-chevron-left"></i> Hexo图床之七牛云
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/08/31/fullscreen-capture/" rel="prev" title="iOS 全屏截图分享组件">
                iOS 全屏截图分享组件 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">张强</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%20%7C%7C%20archive">
              
                  <span class="site-state-item-count">13</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

            <div id="days"></div>
    </script>
    <script language="javascript">
    function show_date_time(){
        window.setTimeout("show_date_time()", 1000);
        BirthDay = new Date("06/10/2014 15:00:00");
        today = new Date();
        timeold = (today.getTime() - BirthDay.getTime());
        sectimeold = timeold / 1000
        secondsold = Math.floor(sectimeold);
        msPerDay = 24 * 60 * 60 * 1000
        e_daysold = timeold / msPerDay
        daysold = Math.floor(e_daysold);
        e_hrsold = (e_daysold - daysold) * 24;
        hrsold = setzero(Math.floor(e_hrsold));
        e_minsold = (e_hrsold - hrsold) * 60;
        minsold = setzero(Math.floor((e_hrsold - hrsold) * 60));
        seconds = setzero(Math.floor((e_minsold - minsold) * 60));
        document.getElementById('days').innerHTML = "已运行" + daysold + "天" + hrsold + "小时" + minsold + "分" + seconds + "秒";
    }
    function setzero(i) {
        if (i<10)
        {i="0" + i};
        return i;
    }
    show_date_time();
</script>

          </nav>

          

          

          
          

          
          
        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#组头的使用"><span class="nav-number">1.</span> <span class="nav-text">组头的使用.</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#自定义组头"><span class="nav-number">1.1.</span> <span class="nav-text">自定义组头</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自定义地址选择器"><span class="nav-number">2.</span> <span class="nav-text">自定义地址选择器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#地址数据"><span class="nav-number">2.1.</span> <span class="nav-text">地址数据</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#模型编写"><span class="nav-number">2.1.1.</span> <span class="nav-text">模型编写</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#数据文件及解析方法"><span class="nav-number">2.1.2.</span> <span class="nav-text">数据文件及解析方法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#自定义cell的改造"><span class="nav-number">2.1.3.</span> <span class="nav-text">自定义cell的改造</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#表单创建类-ComplexFactory"><span class="nav-number">2.1.4.</span> <span class="nav-text">表单创建类 ComplexFactory</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数据验证器"><span class="nav-number">2.2.</span> <span class="nav-text">数据验证器</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2019</span>
  <!--<span class="with-love">
    <i class="fa fa-heart"></i>
  </span>-->
  <span class="with-love">
  (●'◡'●)ﾉ♥
  </span>
  <span class="author" itemprop="copyrightHolder">张强</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">全站总字数&#58;</span>
    
    <span title="全站总字数">16.3k</span>
  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      你是本站第<span class="busuanzi-value" id="busuanzi_value_site_uv"></span>位访客
      
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      文章共批阅<span class="busuanzi-value" id="busuanzi_value_site_pv"></span>次
      
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.2.5/jquery.fancybox.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = '';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: '7FNrT8jBTCLil5J7vFWmPVe3-gzGzoHsz',
        appKey: 'Evbd5Bv3xxN8M3GybtBOyHXU',
        placeholder: '畅所欲言,请尽可能留下真实的邮箱,以便交流.',
        avatar:'wavatar',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("7FNrT8jBTCLil5J7vFWmPVe3-gzGzoHsz", "Evbd5Bv3xxN8M3GybtBOyHXU");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "default";
      
          pbOptions.boxForm = "vertical";
      
          pbOptions.position = "topCenter";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
  </script>

  

  

  

  


  <!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.0.4/jquery.backstretch.min.js"></script>;
  <script>
    $(document).ready(function(){
      $('body').backstretch([
        {url: "/images/background.png", fade: 4000},
        {url: "/images/background01.jpg", fade: 4000},
        {url: "/images/background02.jpg", fade: 4000},
        {url: "/images/background03.jpg", fade: 4000}
      ]);
    });
  </script> -->

</body>
</html>
